﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Com.Ompchina.Lib.UI;
using Com.Ompchina.Lib.Draw;
namespace Com.Ompchina.Web.admin.main
{
    public partial class UcFileUploader : FilesUploader
    {
        /// <summary>
        /// 返回上传控件，只读对象
        /// </summary>
        public FileUpload DefaultFileCtrl { get { return fuFile; } }
        /// <summary>
        /// 此用户控件使用的默认session名
        /// </summary>
        public string DefaultSessionName { get; set; }
        
        /// <summary>
        /// 上传的文件名
        /// </summary>
        private string FileName = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            FileName = string.IsNullOrEmpty(DefaultSessionName) ? base.GetUploadFilename() : base.GetUploadFilename(DefaultSessionName);
            if (!Page.IsPostBack)
            {
                if (string.IsNullOrEmpty(FileName))
                    mvFile.SetActiveView(viewNull);
                else
                {
                    ltl.Text = "<a href='/" + FileName + "' target='_blank'>查看文件</a>";
                    mvFile.SetActiveView(viewFile);
                }
            }
        }

        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            string path = Server.MapPath("~/");
            if (string.IsNullOrEmpty(DefaultSessionName))
            {
                base.DeleteFile(path);
                if (base.GetThumFilename().Length > 0)
                    base.DeleteThumFile(path);
            }
            else
            {
                base.DeleteFile(DefaultSessionName, path);
                if (base.GetThumFilename().Length > 0)
                    base.DeleteThumFile("thum" + DefaultSessionName, path);
            }
            mvFile.SetActiveView(viewNull);
        }
    }
}